﻿using System.Collections.Generic;
using MRGSP.SurveyMaster.Core.Model;
using MRGSP.SurveyMaster.Core.Repository;
using MRGSP.SurveyMaster.Core.Service;

namespace MRGSP.SurveyMaster.Service.Services
{
    public class SurveySessionSevice : ISurveySessionSevice
    {
        private readonly ISurveySessionRepository repo;

        public SurveySessionSevice(ISurveySessionRepository repo)
        {
            this.repo = repo;
        }

        public IPageable<SurveySession> GetPage(int page, int pageSize, long userId)
        {
            return new Pageable<SurveySession>
                       {
                           PageIndex = page,
                           Page = repo.GetPageForUser(page, pageSize, userId),
                           PageCount = ServiceUtils.GetPageCount(pageSize, repo.CountForUser(userId))
                       };
        }

        public void Done(long id)
        {
            repo.Done(id);
        }

        public SurveySession Get(long id)
        {
            return repo.Get(id);
        }

        public long Save(long surveyId, long userId, IEnumerable<Answer> answers)
        {
            return repo.Insert(surveyId, userId, answers);
        }

        public long Update(long sessionId, IEnumerable<Answer> answers)
        {
            return repo.Update(sessionId, answers);
        }

        public IEnumerable<Answer> GetBySessionId(long sessionId)
        {
            return repo.GetBySessionId(sessionId);
        }
    }
}